<#assign entitySchema=info.entitySchema>
<#assign start="#{">
<#assign end="}">

<#-- 判断主键是否有多个，多个的话使用map -->
<#assign prikeySize=0>
<#list entitySchema.propertys as property>
<#if property.prikey?? && property.prikey=="PRI">
<#assign parameterType=property.packageTarget>
</#if> 
</#list>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${info.entityName}Mapper" >
  <resultMap id="${info.entityName}Map" type="${info.entityName}" >
<#list entitySchema.propertys as property>
<#if property.prikey?? && property.prikey=="PRI">
	<id column="${property.columnName}" property="${property.propertyName}"/>
<#else>
	<result column="${property.columnName}"  property="${property.propertyName}"/>
</#if> 
</#list>
  </resultMap>
  
  <sql id="base_column">
<#list entitySchema.propertys as property>
<#if property_has_next>
	${info.joinAlias}.${property.columnName},
<#else>
	${info.joinAlias}.${property.columnName}
</#if>
</#list>
  </sql>
  
  
  <insert id="insert" parameterType="${info.entityName}">
    INSERT INTO ${info.tableName} 
    (
	<#list entitySchema.propertys as property>
    	${property.columnName}<#if property_has_next>,</#if>
    </#list>
    )
    VALUES 
    (
    <#list entitySchema.propertys as property>
    	${start}${property.propertyName}${end}<#if property_has_next>,</#if>
    </#list>
      )
  </insert>
  
  
  <update id="update" parameterType="${info.entityName}">
    UPDATE 
        ${info.tableName}
    SET 
	<#list entitySchema.propertys as property>
    	${property.columnName} = ${start}${property.propertyName}${end}<#if property_has_next>,</#if>
    </#list>
    WHERE <#list entitySchema.propertys as property><#if property.prikey?? && property.prikey=="PRI"><#if property_index gt 0>AND</#if>${property.columnName} = ${start}${property.propertyName}${end}</#if></#list>
  </update>
  
  
  <select id="selectInfoById" parameterType="${parameterType}" resultMap="${info.entityName}Map">
    SELECT  
    		<include refid="base_column" />
    FROM 
    		${info.tableName} ${info.joinAlias}
    WHERE 
    		<#list entitySchema.propertys as property><#if property.prikey?? && property.prikey=="PRI"><#if property_index gt 0>AND</#if>${property.columnName} = ${start}${property.propertyName}${end}</#if></#list>
  </select>
  
  
  <select id="selectPageByQuery" parameterType="${info.entityName}Query" resultMap="${info.entityName}Map">
    SELECT  
    		<include refid="base_column" />
    FROM 
    		${info.tableName} ${info.joinAlias}
    LIMIT ${start}offset${end}, ${start}pageSize${end}
  </select>
  
  
  <select id="countPageByQuery" parameterType="${info.entityName}Query" resultType="java.lang.Integer">
    SELECT  
    		count(*)
    FROM 
    		${info.tableName} ${info.joinAlias}
  </select>
  
  
  <select id="selectInfoByQuery" parameterType="${info.entityName}Query" resultMap="${info.entityName}Map">
    SELECT  
    		<include refid="base_column" />
    FROM 
    		${info.tableName} ${info.joinAlias}
  </select>
  
  
  <delete id="delete" parameterType="${info.entityName}">
    DELETE FROM 
    		${info.tableName} 
    WHERE 
    		<#list entitySchema.propertys as property><#if property.prikey?? && property.prikey=="PRI"><#if property_index gt 0>AND</#if>${property.columnName} = ${start}${property.propertyName}${end}</#if></#list>
  </delete>
</mapper>